package cn.tonyandmoney.voicenotes.notes.config

import android.os.Environment
import cn.tonyandmoney.baidu.asr.config.IRecogParams
import com.baidu.speech.asr.SpeechConstant
import java.io.File

/**
 * Created by niantuo on 2018/3/16.
 * 离在线融合的配置
 *  * {"accept-audio-data":false,"grammar":"asset:\/\/\/baidu_speech_grammar.bsg",
 * "vad.endpoint-timeout":0,"pid":1536,"accept-audio-volume":false,
 * "nlu":"enable-all"}
 * 不知道为什么，如果开启离在线融合，那么离线语义识别则不能成功
 * 如果只有在线模式，则能实现离线语义识别
 */
class RecogParams : IRecogParams {

    companion object {
        val mRoot = Environment.getExternalStorageDirectory().absolutePath + "/VoiceNote/"
        val pcm = "pcm"
        @Volatile var fileName:String?=null
    }

    private val offlineParams = mutableMapOf(SpeechConstant.DECODER to 0,
            SpeechConstant.ASR_OFFLINE_ENGINE_GRAMMER_FILE_PATH to "asset:///baidu_speech_grammar.bsg")

    private val allParams = hashMapOf(
            SpeechConstant.DECODER to 0,
            SpeechConstant.ASR_OFFLINE_ENGINE_GRAMMER_FILE_PATH to "asset:///baidu_speech_grammar.bsg",
            SpeechConstant.NLU to "enable-all",
            "vad.endpoint-timeout" to 0,
            "pid" to 1936,
            SpeechConstant.ACCEPT_AUDIO_VOLUME to false,
            "disable-punctuation" to true)


    /**
     * 如果不用离线，则返回null
     */
    override fun fetchOfflineParams(): Map<String, Any>? {
        return offlineParams
    }

    /**
     * 保存的原始文件
     * 分段文件自己实现保存操作
     * 接收数据，但是不保存原始数据
     */
    override fun fetchParams(): Map<String, Any> {
        val paramMap = HashMap<String, Any>()
        paramMap.putAll(allParams)
        paramMap[SpeechConstant.ACCEPT_AUDIO_DATA] = true
//        paramMap[SpeechConstant.OUT_FILE] = mRoot + fileName
        return paramMap
    }

}